package com.codeye.spider.siteName;

import java.util.Map;

import com.codeye.spider.Queue;

public class Spider_sn implements Runnable  {
	
	private int SpiderNum = 0;
	public Spider_sn(int SpiderNum){  
	      this.SpiderNum = SpiderNum; 
	}  
	
	public void run() {
		int reTryTimes = 0;
		while (!Queue.isEmpty()) {
			String htmlUrl = Queue.getAndRemoveFirstElem();
			Map<String,String> rmap = Actions_sn.grabWebName(htmlUrl, SpiderNum, Queue.size());
			while(reTryTimes != 3 && (rmap.get(htmlUrl).equals("") || rmap.get(htmlUrl).equals("null") || rmap.get(htmlUrl).equals("unknow") ||
					rmap.get(htmlUrl).equals("none"))){
				rmap = Actions_sn.grabWebName(htmlUrl, SpiderNum, Queue.size());
				reTryTimes += 1;
			}
			if(rmap.get(htmlUrl).equals("") || rmap.get(htmlUrl).equals("null") || rmap.get(htmlUrl).equals("unknow") ||
					rmap.get(htmlUrl).equals("none")){
				System.err.println("▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇SpiderNum 【"+SpiderNum+"】▇▇▇▇▇▇▇▇ ：" + htmlUrl);
			} else {
				System.out.println("●●●●●●●●●●SpiderNum 【"+SpiderNum+"】●●●●●●●●●●● ：" + htmlUrl);
			}
			
			Queue.addElem(rmap);
			
		}
	}
}
